package com.itheima.manager.util;

import com.itheima.manager.domain.ManagerMan;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Scanner;

public class LoginStudnetProp {
    //北京地铁管理系统登录功能实现
    private static boolean flag;


    public static boolean login() {
        FileReader fr = null;
        try {
            flag = false;
            Scanner sc = new Scanner(System.in);
            BufferedReader br = new BufferedReader(new FileReader
                    ("北京地铁管理系统\\managers.txt"));
            System.out.println("请输入工号: ");
            String id = sc.next();
            System.out.println("请输入姓名: ");
            String username = sc.next();
            ArrayList<ManagerMan> list = new ArrayList<ManagerMan>();
            String manager;
            while ((manager = br.readLine()) != null) {
                String[] managerSplit = manager.split(",");
                list.add(new ManagerMan(managerSplit[0], managerSplit[1], managerSplit[2], managerSplit[3]));
            }
            list.forEach(managerman -> {
                if (managerman != null && managerman.getId().equals(id) && managerman.getName().equals(username)) {
                    flag = true;
                }
            });
        } catch (IOException e) {
            //e.printStackTrace();
        } finally {
            if (fr != null) {
                try {
                    fr.close();
                } catch (IOException e) {
                    //e.printStackTrace();
                }
            }
            if (flag) {
                System.out.println("========登录验证成功========");
            } else {
                System.out.println("========登录验证失败========");
            }

            return flag;
        }
    }
}
